home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zfdctd.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.3 KB  |  100 lines

  1. /* Copyright (C) 1994, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: zfdctd.c,v 1.3 2000/09/19 19:00:53 lpd Exp $ */
  20. /* DCTDecode filter creation */
  21. #include "memory_.h"
  22. #include "stdio_.h"        /* for jpeglib.h */
  23. #include "jpeglib_.h"
  24. #include "ghost.h"
  25. #include "oper.h"
  26. #include "gsmalloc.h"        /* for gs_memory_default */
  27. #include "strimpl.h"
  28. #include "sdct.h"
  29. #include "sjpeg.h"
  30. #include "ialloc.h"
  31. #include "ifilter.h"
  32. #include "iparam.h"
  33.  
  34. /* Import the parameter processing procedure from sddparam.c */
  35. stream_state_proc_put_params(s_DCTD_put_params, stream_DCT_state);
  36.  
  37. /* <source> <dict> DCTDecode/filter <file> */
  38. /* <source> DCTDecode/filter <file> */
  39. private int
  40. zDCTD(i_ctx_t *i_ctx_p)
  41. {
  42.     os_ptr op = osp;
  43.     gs_memory_t *mem = &gs_memory_default;
  44.     stream_DCT_state state;
  45.     dict_param_list list;
  46.     jpeg_decompress_data *jddp;
  47.     int code;
  48.     const ref *dop;
  49.     uint dspace;
  50.  
  51.     /* First allocate space for IJG parameters. */
  52.     jddp = (jpeg_decompress_data *)
  53.     gs_alloc_bytes_immovable(mem, sizeof(*jddp), "zDCTD");
  54.     if (jddp == 0)
  55.     return_error(e_VMerror);
  56.     if (s_DCTD_template.set_defaults)
  57.     (*s_DCTD_template.set_defaults) ((stream_state *) & state);
  58.     state.data.decompress = jddp;
  59.     jddp->memory = state.jpeg_memory = mem;    /* set now for allocation */
  60.     jddp->scanline_buffer = NULL;    /* set this early for safe error exit */
  61.     state.report_error = filter_report_error;    /* in case create fails */
  62.     if ((code = gs_jpeg_create_decompress(&state)) < 0)
  63.     goto fail;        /* correct to do jpeg_destroy here */
  64.     /* Read parameters from dictionary */
  65.     if (r_has_type(op, t_dictionary))
  66.     dop = op, dspace = r_space(op);
  67.     else
  68.     dop = 0, dspace = 0;
  69.     if ((code = dict_param_list_read(&list, dop, NULL, false, iimemory)) < 0)
  70.     goto fail;
  71.     if ((code = s_DCTD_put_params((gs_param_list *) & list, &state)) < 0)
  72.     goto rel;
  73.     /* Create the filter. */
  74.     jddp->template = s_DCTD_template;
  75.     code = filter_read(i_ctx_p, 0, &jddp->template,
  76.                (stream_state *) & state, dspace);
  77.     if (code >= 0)        /* Success! */
  78.     return code;
  79.     /*
  80.      * We assume that if filter_read fails, the stream has not been
  81.      * registered for closing, so s_DCTD_release will never be called.
  82.      * Therefore we free the allocated memory before failing.
  83.      */
  84. rel:
  85.     iparam_list_release(&list);
  86. fail:
  87.     gs_jpeg_destroy(&state);
  88.     gs_free_object(mem, jddp, "zDCTD fail");
  89.     return code;
  90. }
  91.  
  92. /* ------ Initialization procedure ------ */
  93.  
  94. const op_def zfdctd_op_defs[] =
  95. {
  96.     op_def_begin_filter(),
  97.     {"2DCTDecode", zDCTD},
  98.     op_def_end(0)
  99. };
  100.